package me.boot.web.common.config;

import lombok.extern.slf4j.Slf4j;
import me.boot.common.context.ContextConst;
import me.boot.common.context.ContextUtil;
import me.boot.db.mybatis.propertites.DbProperties;
import me.boot.db.mybatis.propertites.TenantMode;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.boot.autoconfigure.AutoConfigureOrder;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Slf4j
@AutoConfigureOrder(-100)
@Configurable
public class WebCommonConfiguration {

    @Resource
    DbProperties dbProperties;

    @PostConstruct
    void init() {
        log.info("Init WebCommonConfiguration");

        TenantMode tenantMode = dbProperties.getTenant().getMode();
        ContextUtil.set(ContextConst.CONTEXT_TENANT_MODE, tenantMode);

        log.info("租户模式: {}", tenantMode);
    }
}
